package com.naiterui.ehp.bs.b2c.product.controller.inner;

import java.util.List;
import java.util.Set;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.naiterui.ehp.bp.bo.b2c.cms.MedicineBO;
import com.naiterui.ehp.bp.constants.SwaggerTag;
import com.naiterui.ehp.bp.support.exception.PublicService;
import com.naiterui.ehp.bp.support.exception.ResponseVO;
import com.naiterui.ehp.bp.support.mvc.RequestHeaderDecode;
import com.naiterui.ehp.bs.b2c.product.service.IInnerMedicineService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@Api(tags = SwaggerTag.DOCTOR + SwaggerTag.MEDICINE_DRUG)
@Validated
@RestController
@RequestMapping("b2c/inner/cms/medicine")
public class InnerMedicineController {
    private static final Logger LOGGER = LoggerFactory.getLogger(InnerMedicineController.class);
    @Autowired
    private IInnerMedicineService innerMedicineService;

    /**
     * 保存更新商品
     *
     * @param operator
     * @param medicine
     *
     * @return
     */
    @ApiOperation(value = "保存更新商品")
    @PostMapping
    public ResponseVO<Long> saveOrUpdate(@RequestHeaderDecode @NotEmpty(message = "操作用户不能为null") String operator,
                                         @Valid @RequestBody MedicineBO medicine) {
        LOGGER.info("保存更新商品 请求参数：operator = {}, medicine = {}", operator, medicine);
        Long productId = this.innerMedicineService.saveOrUpdate(operator, medicine);
        return PublicService.returnResponseVO(productId);
    }

    @ApiOperation(value = "根据商品ID获取商品列表")
    @ApiImplicitParam(name = "pIdSet", value = "药品ID集合", paramType = "body", dataType = "array", required = true)
    @PostMapping("/getByIds")
    public ResponseVO<List<MedicineBO>> getByIds(@Valid @RequestBody Set<Long> pIdSet) {
        return PublicService.returnResponseVO(this.innerMedicineService.getByIds(pIdSet));
    }
}
